/**
* Oxide
*
* Copyright (c) 2011 Dinosaur Kick Pty Ltd, All rights reserved.
*
* This source code is made available under the "Modified BSD" licensing arrangement.
* See license.txt for details.
*/
// ----------------------------------------------------------------------------
#include <string>
#include <ostream>
#include "oxide-common/str.hpp"
// ----------------------------------------------------------------------------
#ifndef O2_COMMON_TOKEN_IDENTITY_INC
#define O2_COMMON_TOKEN_IDENTITY_INC
namespace o2 {
// ----------------------------------------------------------------------------

enum token_identity
{
	TOK_EOF = -1,

	TOK_SEMICOLON = ';',
	TOK_COLON = ':',
	TOK_DOT = '.',
	TOK_COMMA = ',',

	// Assignment operators ...
	TOK_ASSIGN = '=',
	
	// Math operators ...
	TOK_MUL = '*',
	TOK_DIV = '/',
	TOK_POS = '+',
	TOK_NEG = '-',
	
	TOK_LT = '<',
	TOK_GT = '>',
	
	// Paired operators ...
	TOK_OPEN_BRACE = '{',
	TOK_CLOSE_BRACE = '}',
	TOK_OPEN_PAREN = '(',
	TOK_CLOSE_PAREN = ')',
	TOK_OPEN_BRACKET = '[',
	TOK_CLOSE_BRACKET = ']',
	
	// Operators ...
	TOK_INC = 256,
	TOK_DEC,
	TOK_LTE,
	TOK_GTE,
	TOK_SHL,
	TOK_SHR,
	
	// Literals ...
	TOK_STRING,
	TOK_INTEGER_HEX,
	TOK_INTEGER_BIN,
	TOK_INTEGER_OCT,
	TOK_INTEGER_DEC,
	TOK_FLOAT,
	TOK_FIXED,

	// Keywords ...
	TOK_CLASS,
	TOK_METHOD,
	TOK_PROPERTY,
	TOK_VAR,
	TOK_ACCESS_MODIFIER,
	TOK_STATIC,
	TOK_ABSTRACT,
	TOK_FINAL,

	// ...
	TOK_IDENTIFIER,
	TOK_LINE_COMMENT,
	TOK_BLOCK_COMMENT,
	
	TOK_UNKNOWN
};

// ----------------------------------------------------------------------------

template <typename StringT>
StringT token_identity_name(token_identity identity)
{
	typedef StringT string_type;
	
	switch (identity)
	{
		O2_STR_ENUM(TOK_EOF);
		O2_STR_ENUM(TOK_SEMICOLON);
		O2_STR_ENUM(TOK_COLON);
		O2_STR_ENUM(TOK_DOT);
		O2_STR_ENUM(TOK_COMMA);
		O2_STR_ENUM(TOK_ASSIGN);
		O2_STR_ENUM(TOK_MUL);
		O2_STR_ENUM(TOK_DIV);
		O2_STR_ENUM(TOK_POS);
		O2_STR_ENUM(TOK_NEG);
		O2_STR_ENUM(TOK_LT);
		O2_STR_ENUM(TOK_GT);
		O2_STR_ENUM(TOK_OPEN_BRACE);
		O2_STR_ENUM(TOK_CLOSE_BRACE);
		O2_STR_ENUM(TOK_OPEN_PAREN);
		O2_STR_ENUM(TOK_CLOSE_PAREN);
		O2_STR_ENUM(TOK_OPEN_BRACKET);
		O2_STR_ENUM(TOK_CLOSE_BRACKET);
		O2_STR_ENUM(TOK_INC);
		O2_STR_ENUM(TOK_DEC);
		O2_STR_ENUM(TOK_LTE);
		O2_STR_ENUM(TOK_GTE);
		O2_STR_ENUM(TOK_SHL);
		O2_STR_ENUM(TOK_SHR);
		O2_STR_ENUM(TOK_STRING);
		O2_STR_ENUM(TOK_INTEGER_HEX);
		O2_STR_ENUM(TOK_INTEGER_BIN);
		O2_STR_ENUM(TOK_INTEGER_OCT);
		O2_STR_ENUM(TOK_INTEGER_DEC);
		O2_STR_ENUM(TOK_FLOAT);
		O2_STR_ENUM(TOK_FIXED);
		O2_STR_ENUM(TOK_CLASS);
		O2_STR_ENUM(TOK_METHOD);
		O2_STR_ENUM(TOK_PROPERTY);
		O2_STR_ENUM(TOK_VAR);
		O2_STR_ENUM(TOK_ACCESS_MODIFIER);
		O2_STR_ENUM(TOK_STATIC);
		O2_STR_ENUM(TOK_ABSTRACT);
		O2_STR_ENUM(TOK_FINAL);
		O2_STR_ENUM(TOK_IDENTIFIER);
		O2_STR_ENUM(TOK_LINE_COMMENT);
		O2_STR_ENUM(TOK_BLOCK_COMMENT);
		case TOK_UNKNOWN:
			; // Allow fall through ...
	}

	return O2_CSTR("TOK_UNKNOWN");
}

// ----------------------------------------------------------------------------

template <typename CharT, typename TraitsT>
std::basic_ostream<CharT, TraitsT>& operator<< (std::basic_ostream<CharT, TraitsT>& stream, token_identity identity)
{
	return stream << token_identity_name<std::basic_string<CharT> >(identity);
}

// ----------------------------------------------------------------------------
} // namespace o2
#endif // O2_COMMON_TOKEN_IDENTITY_INC
// ----------------------------------------------------------------------------
